<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link rel="stylesheet" href="../../../layui/css/layui.css" media="all">
<title>材料修改</title>
</head>

<body>

	<fieldset class="layui-elem-field layui-field-title"
		style="margin-top: 20px;">
		<legend>材料修改列表</legend>
	</fieldset>

	<form class="layui-form" action="../../../materials/update.action"
		method="post" id="myform">
		<input type="hidden" id="matId" name="matId">
		<div class="layui-form-item">
			<label class="layui-form-label">材料名称</label>
			<div class="layui-input-block">
				<input type="text" name="matName" id="matName"
					lay-verify="required" placeholder="请输入" autocomplete="off"
					class="layui-input" maxlength="10">
			</div>
		</div>
		<input type="hidden" id="typeIds" name="typeIds">
		<div class="layui-form-item">
			<label class="layui-form-label">材料类型</label>
			<div class="layui-input-block">
				<select name="matTypeId" id="matTypeId" required lay-verify="required"
					autocomplete="off" class="layui-input">
					<option></option>
				</select>
			</div>
		</div>
		<div class="layui-form-item">
			<label class="layui-form-label">材料价格</label>
			<div class="layui-input-block">
				<input onblur="price()"  type="text" name="matPrice" id="matPrice"
					lay-verify="required" placeholder="请输入" autocomplete="off"
					class="layui-input">
			</div>
		</div>
		<div class="layui-form-item layui-form-text">  
         	<label class="layui-form-label">材料说明</label>  
          	<div class="layui-input-block">  
            	<textarea id="matState" name="matState" 
            	lay-verify="required" class="layui-textarea" 
            	maxlength="150" placeholder="请输入"></textarea>
          	</div>  
        </div>
		<!-- 提交重置 -->
		<div class="layui-form-item">
			<div class="layui-input-block">
				<input  type="submit" class="layui-btn" lay-submit="" id="tijiao"
					lay-filter="materialsUpdate" value="立即提交">
				<button type="reset" class="layui-btn layui-btn-primary">重置</button>
			</div>
		</div>
	</form>

	<script src="../../../layui/layui.js"></script>
	<script type="text/javascript" src="../../../res/wzw/js/jquery.min.1.6.4.js"></script>
	<script src="../../../res/wzw/js/jquery-1.10.2.js"></script>

	<script>
	function price(){
	    var price = document.getElementById('matPrice').value;
	    var a=price.split(".")
	    if(price<=0||price>=1000){
	       $("#matPrice").attr("placeholder","价格范围1-999￥");
	       document.getElementById('matPrice').value="";
	       return false;
	    }else{
	   		var num = new Number(price);
	   		document.getElementById('matPrice').value=""+num.toFixed(2)+""
	    }
	    
	    /* if(price=="NaN"){
	    	$("#matPrice").attr("placeholder","请符合价格规范");
	       	document.getElementById('matPrice').value="";
	       	return false;
	    } */
	}
	
	layui.use(['form', 'layer'], function(){
	  var form = layui.form
	  ,layer = layui.layer
	  ,$ = layui.$;
	  
	  form.on('submit(materialsUpdate)',function(){
		 parent.location.reload(); // 父页面刷新
	  });
	  
	  $("#tijiao").click(function(){
		  var price = document.getElementById('matPrice').value;
		  alert(price);
		 if(price=="NaN"){
			 alert(price);
			 $("#matPrice").attr("placeholder","请符合价格规范");
		     document.getElementById('matPrice').value="";
		     return false;
		 }
	  });
	  
	  var url = "../../../materials/findAllType.action";
		$.post(url,null,function(data){
			for(var i=0;i<data.length;i++){
				$("#matTypeId").append("<option value="+data[i].matTypeId+">"+data[i].matTypeName+"</option>");
			}
			//form表单重新渲染
			form.render();
			var ss = document.getElementById('typeIds').value;
			document.getElementById('matTypeId').value=ss;
			//form表单重新渲染
			form.render();
		},dataType="JSON");
	});
</script>

</body>
</html>